<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>

<body>
    <input type="button" value="改变背景颜色" onclick="changeBack()">
    <script>
        function color() {
            //16进制随机数生成 颜色值
            var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            var color = '#' + r.toString(16) + g.toString(16) + b.toString(16);
            return color;
        }
        // console.log(color()); //调用函数生成随8机颜色

        function changeBack() {
            var body = document.getElementsByTagName('body');
            body[0].style.backgroundColor = color()
        }
    </script>
</body>

</html>